using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_JXC_AccountSubjectTotal : Admin, IRequiresSessionState
{
	protected ScriptManager sm;
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected DropDownList ddlYear;
	protected DropDownList ddlBeginMonth;
	protected DropDownList ddlEndMonth;
	protected DropDownList ddlSubject;
	protected TextBox txtSearchSalerName;
	protected Button btnSearch;
	protected UpdatePanel UpdatePanel1;
	protected Repeater rptList;
	protected UpdatePanel upList;
	private string linkHead = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(43))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_JXC_AccountSubjectTotal");
				base.WriteRightErrMsg();
			}
			string sql = "select top 1  DATEPART (YYYY,InputDate) as yearNum from HLJXC_View_AccountAoucherItemSubjcet order by DATEPART (YYYY,InputDate) asc";
			DataTable dataTable = this.conn.GetDataTable(sql);
			int year = DateTime.Now.Year;
			this.ddlYear.Items.Clear();
			if (dataTable.Rows.Count > 0)
			{
				int num = Convert.ToInt32(dataTable.Rows[0]["yearNum"].ToString());
				if (num < year)
				{
					for (int i = num; i <= year; i++)
					{
						ListItem item = new ListItem(i.ToString(), i.ToString());
						this.ddlYear.Items.Add(item);
					}
				}
				else
				{
					this.ddlYear.Items.Add(new ListItem(year.ToString(), year.ToString()));
				}
			}
			else
			{
				this.ddlYear.Items.Add(new ListItem(year.ToString(), year.ToString()));
			}
			this.ddlSubjcetList();
			this.BindData();
		}
	}
	private void ddlSubjcetList()
	{
		this.ddlSubject.Items.Clear();
		string strWhere = "AccountSParentID=0 order by AccountSRootID,AccountSParentID desc";
		DataTable dataTable = BLLInstance.BllAccountSubject.GetList(strWhere).Tables[0];
		foreach (DataRow dataRow in dataTable.Rows)
		{
			int parentID = dataRow["AccountSubjectID"].ToInt32(new int[0]);
			BLLInstance.BllAccountSubject.BindSubjcet(this.ddlSubject, parentID, 1, "");
		}
		this.ddlSubject.Items.Insert(0, new ListItem("全部", "0"));
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("selYear");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddlYear.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddlYear.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and (DATEPART (YYYY,InputDate)=" + text2 + ")";
			this.linkHead = this.linkHead + "&selYear=" + text2;
		}
		string text3 = Fetch.Get("BeginMonth");
		if (!string.IsNullOrEmpty(text3))
		{
			this.ddlBeginMonth.ddlSelect(text3);
		}
		else
		{
			text3 = this.ddlBeginMonth.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and DATEPART(MM,InputDate)>=" + text3;
			this.linkHead = this.linkHead + "&BeginMonth=" + text3;
		}
		string text4 = Fetch.Get("EndMonth");
		if (!string.IsNullOrEmpty(text4))
		{
			this.ddlEndMonth.ddlSelect(text4);
		}
		else
		{
			text4 = this.ddlEndMonth.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			if (!string.IsNullOrEmpty(text3))
			{
				if (Convert.ToInt32(text3) > Convert.ToInt32(text4))
				{
					this.WriteErrMsg("", "开始的月份不能大于结束月份！", "");
				}
			}
			text = text + " and DATEPART(MM,InputDate)<=" + text4;
			this.linkHead = this.linkHead + "&EndMonth=" + text4;
		}
		string text5 = Fetch.Get("subjcetID");
		if (!string.IsNullOrEmpty(text5))
		{
			this.ddlSubject.ddlSelect(text5);
		}
		else
		{
			text5 = this.ddlSubject.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text5) && text5 != "0")
		{
			text = text + " and AAItemAccountSID=" + text5;
			this.linkHead = this.linkHead + "&subjcetID=" + text5;
		}
		string text6 = Fetch.Get("ownername");
		if (!string.IsNullOrEmpty(text6))
		{
			this.txtSearchSalerName.Text = text6;
		}
		else
		{
			text6 = this.txtSearchSalerName.Text;
		}
		if (!string.IsNullOrEmpty(text6))
		{
			text = text + " and OwnerID in (select UserID from HL_User where UserName like '%" + text6 + "%')";
			this.linkHead = this.linkHead + "&ownername=" + text6;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		return "order by AAItemAccountSID asc";
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		string text = " from HLJXC_View_AccountAoucherItemSubjcet where 1=1 ";
		string text2 = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,AAItemAccountSID,AccountSNumber,AccountSName,DATEPART (YYYY,InputDate) as yearNum,DATEPART(MM,InputDate) as monthNum,SUM(BorrowPrice) as BorrowPrice,SUM(LoanPrice) as LoanPrice,(select UserName from HL_User where UserID=OwnerID) as OwnerName ";
		string sql = string.Concat(new string[]
		{
			"select ",
			text2,
			text,
			query,
			"  group by AAItemAccountSID,AccountSNumber,AccountSName,DATEPART (YYYY,InputDate),DATEPART(MM,InputDate),OwnerID"
		});
		DataTable dataTable = this.conn.GetDataTable(sql);
		this.rptList.DataSource = dataTable;
		this.rptList.DataBind();
		string b = "";
		for (int i = 0; i < this.rptList.Items.Count; i++)
		{
			Label label = (Label)this.rptList.Items[i].FindControl("lblRow");
			HiddenField hiddenField = (HiddenField)this.rptList.Items[i].FindControl("hfAAItemAccountSID");
			Label label2 = (Label)this.rptList.Items[i].FindControl("lblAccountSNumber");
			Label label3 = (Label)this.rptList.Items[i].FindControl("lblAccountSName");
			Label label4 = (Label)this.rptList.Items[i].FindControl("lblBorrowPrice");
			Label label5 = (Label)this.rptList.Items[i].FindControl("lblLoanPrice");
			HiddenField hiddenField2 = (HiddenField)this.rptList.Items[i].FindControl("hfBorrowPrice");
			HiddenField hiddenField3 = (HiddenField)this.rptList.Items[i].FindControl("hfLoanPrice");
			Label label6 = (Label)this.rptList.Items[i].FindControl("lblLend");
			Label label7 = (Label)this.rptList.Items[i].FindControl("lblMoney");
			label.Text = (i + 1).ToString();
			string value = hiddenField.Value;
			if (value == b)
			{
				label2.Text = "";
				label3.Text = "";
			}
			b = value;
			if (label7 != null)
			{
				decimal d = 0m;
				if (!string.IsNullOrEmpty(hiddenField2.Value))
				{
					d = Convert.ToDecimal(hiddenField2.Value);
				}
				decimal d2 = 0m;
				if (!string.IsNullOrEmpty(hiddenField3.Value))
				{
					d2 = Convert.ToDecimal(hiddenField3.Value);
				}
				decimal num = d - d2;
				label4.Text = d.ToString();
				label5.Text = d2.ToString();
				if (num > 0m)
				{
					label6.Text = "借";
				}
				else
				{
					if (num < 0m)
					{
						label6.Text = "贷";
					}
					else
					{
						if (num == 0m)
						{
							label6.Text = "平";
						}
					}
				}
				label7.Text = Math.Abs(num).ToString();
			}
		}
		if (dataTable.Rows.Count == 0)
		{
			Label label8 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblFooterDate");
			label8.Text = "<tr><th colspan='9' align='center' style='color:Black; font-style:normal; font-weight:lighter'>没有您要查的数据！</th></tr>";
		}
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindData();
	}
	protected void ddlSubject_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.BindData();
	}
}
